"""
http请求响应示例
"""
from socket import *

sock = socket()
sock.bind(("0.0.0.0",8888))
sock.listen(5)

while True:
    # 等待浏览器连接
    connfd,addr = sock.accept()
    print("Connect from",addr)

    # 接收HTTP请求 request
    data = connfd.recv(1024)
    print(data.decode())

    # 发送响应
    response = """HTTP/1.1 200 OK
Content-Type:text/html

Hello World!
"""
    connfd.send(response.encode())
    connfd.close()

sock.close()